﻿using B.S.BaseData.Api.Write.Applicantion.Command;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.Infrastructure.Interface;
using B.S.BataBase.Domain;
using MediatR;

namespace B.S.BaseData.Api.Write.Applicantion.Handler
{
    public class RoleDeleteCommandHandler : IRequestHandler<RoleDeleteCommand, APIResult<int>>
    {
        private readonly IBaseRepository<RoleModel> _repository;
        public RoleDeleteCommandHandler(IBaseRepository<RoleModel> repository)
        {
            _repository = repository;
        }

        public async Task<APIResult<int>> Handle(RoleDeleteCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result=new APIResult<int>();
            var list =await _repository.GetValues(x=>x.Id==request.Id);
            list.IsDeleted=true;
            await _repository.UpdateAsync(list);
            result.Code = ApiEnum.Success;
            result.Msg = "角色信息删除成功";
            result.Data = 1;
            return await Task.FromResult(result);
        }
    }
}
